'use strict'
// Template version: 1.3.1
// see http://vuejs-templates.github.io/webpack for documentation.

const path = require('path')
const glob = require('glob');

//获取所有入口文件
function getEntry(globPath)  {
    const entries = glob.sync(globPath).reduce((result, entry) => {
        const moduleName = path.basename(path.dirname(entry)); // 获取模块名称
        result[moduleName] = entry;
        return result
    }, {});
    return entries;
}
var pages = getEntry('./src/**/index.html');


//每个入口页面生成一个入口添加到build中
const build ={};
for (var pathname in pages) {
  var tmp='';
    tmp = pages[pathname].split('/').splice(-3)[1];
      build[tmp] = path.resolve(__dirname, '../src/webapp/' + tmp + '.html');
}
module.exports = {
  dev: {// 开发过程中使用的配置

    // Paths
    assetsSubDirectory: 'static',
    assetsPublicPath: '/',
    proxyTable: {
        '/api': {
            target: 'http://localhost:8080/api/add',
            changeOrigin: true,
            pathRewrite: {
                '^/api': '/api'
            }
        }
    },// 请求代理表，在这里可以配置特定的请求代理到对应的API接口

    // Various Dev Server settings
      disableHostCheck: true,
      host:"0.0.0.0", // can be overwritten by process.env.HOST
    port: 8081, // can be overwritten by process.env.PORT, if port is in use, a free one will be determined
    autoOpenBrowser: false,
    errorOverlay: true,
    notifyOnErrors: true,
    poll: false, // https://webpack.js.org/configuration/dev-server/#devserver-watchoptions-

    // Use Eslint Loader?
    // If true, your code will be linted during bundling and
    // linting errors and warnings will be shown in the console.
    useEslint: false,
    // If true, eslint errors and warnings will also be shown in the error overlay
    // in the browser.
    showEslintErrorsInOverlay: false,

    /**
     * Source Maps
     */

    // https://webpack.js.org/configuration/devtool/#development
    devtool: 'cheap-module-eval-source-map',

    // If you have problems debugging vue-files in devtools,
    // set this to false - it *may* help
    // https://vue-loader.vuejs.org/en/options.html#cachebusting
    cacheBusting: true,

    cssSourceMap: true
  },

  build: {// 构建产品时使用的配置
    // Template for index.html
      index: build,

    // Paths
    assetsRoot: path.resolve(__dirname, '../src/webapp'),
    assetsSubDirectory: 'assets', //webpack编译输出的二级文件夹
    assetsPublicPath: '/',  //输出的发布路径

    /**
     * Source Maps
     */

    productionSourceMap: true,//使用SourceMap
    // https://webpack.js.org/configuration/devtool/#production
    devtool: '#source-map',

    // Gzip off by default as many popular static hosts such as
    // Surge or Netlify already gzip all static assets for you.
    // Before setting to `true`, make sure to:
    // npm install --save-dev compression-webpack-plugin
    productionGzip: false,
    productionGzipExtensions: ['js', 'css'],//gzip模式下的扩展名

    // Run the build command with an extra argument to
    // View the bundle analyzer report after build finishes:
    // `npm run build --report`
    // Set to `true` or `false` to always turn it on or off
    bundleAnalyzerReport: process.env.npm_config_report
  }
}
